package com.xiaocai.objview.gl;

import android.opengl.GLES20;
import android.util.Log;

import com.xiaocai.objview.utils.Constants;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class VertexArray {

    static {
        System.loadLibrary("hello");
    }

    private static final String TAG = "VertexArray";

    private FloatBuffer floatBuffer;

    private float[] vertexData;

    private native void configVertexAttribPointer(int attributeLocation,
                                                  int componentCount, int stride,
                                                  int dataOffset, float[] vertexData);

    public VertexArray(float[] vertexData) {
        /*floatBuffer = ByteBuffer.allocateDirect(vertexData.length * Constants.BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer()
                .put(vertexData);*/

        this.vertexData = vertexData;
    }

    public void setVertexAttribPointer(int dataOffset, int attributeLocation, int componentCount, int stride) {
//        floatBuffer.position(dataOffset);
//        GLES20.glVertexAttribPointer(attributeLocation, componentCount, GLES20.GL_FLOAT, false, stride, floatBuffer);
        configVertexAttribPointer(attributeLocation, componentCount, stride, dataOffset, vertexData);
        GLES20.glEnableVertexAttribArray(attributeLocation);
//        floatBuffer.position(0);
    }

    public void updateBuffer(float[] vertexData, int start, int count) {
//        floatBuffer.position(start);
//        floatBuffer.put(vertexData, start, count);
//        floatBuffer.position(0);
    }
}
